﻿#include"homework.h"
int num = 2001;
void inputTea(Teacher tArr[], int len)
{
	string nameSeed = "ABC";
	//给老师赋值
	for (int i = 0; i < len; i++)
	{
		tArr[i].name = "Teacher_";
		tArr[i].name += nameSeed[i];
		string nameSeed1 = "ABCDE";
		//通过循环给学生赋值`
		for (int j = 0; j < 5; j++)
		{
			
			tArr[i].stu[j].name = "Student__";
			tArr[i].stu[j].name += nameSeed1[j];
			int random = rand() % 101;
			tArr[i].stu[j].score = random;
			tArr[i].stu[j].num = num++;
		}
	}
}

void swap(Teacher tArr[], int len)
{
	int i = 0;
	while (i < len)
	{
		for (int m = 0; m < 5; m++)
		{
			for (int j = 0; j < 5 - m - 1; j++)
			{
				if (tArr[i].stu[j].score < tArr[i].stu[j + 1].score)
				{
					Student temp = tArr[i].stu[j]; 
					tArr[i].stu[j] = tArr[i].stu[j + 1];
					tArr[i].stu[j + 1] = temp;
				}
			}
		}
		i++;
	}

}

	void print(Teacher tArr[], int len) {
		for (int i = 0; i < len; i++)
		{
			cout << tArr[i].name << ":" << endl;
			for (int j = 0; j < 5; j++)
			{
				cout << "\t" << tArr[i].stu[j].name
					<< "--" << tArr[i].stu[j].num
					<< "--" << tArr[i].stu[j].score
					<< endl;
			}
		}
	}


int main()
{
	//生成随机数
	srand((unsigned int)time(NULL));
	//创建3名老师的数组
	Teacher tArr[3];
	//通过数组给3名老师赋值
	int len = sizeof(tArr) / sizeof(tArr[0]);
	inputTea(tArr, len);
	swap(tArr, len);
	print(tArr, len);
	

	return 0;
}